package com.qf.service.impl;

import com.qf.mapper.ClassroomMapper;
import com.qf.pojo.Classroom;
import com.qf.service.ClassroomService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassroomServiceImpl implements ClassroomService {
    @Autowired
    ClassroomMapper classroomMapper;
    @Override
    public ResultMsg selectAll(int page, int limit) {
        List<Classroom> classroomList=classroomMapper.selectAll((page-1)*limit,limit);
        return ResultMsg.SUCCESS(0,classroomList,classroomList.size());
    }

    @Override
    public ResultMsg selectOne(int classroomId) {
        Classroom classroom=classroomMapper.selectOne(classroomId);
        return ResultMsg.SUCCESS(classroom);
    }

    @Override
    public ResultMsg update(Classroom classroom) {
        if(classroomMapper.update(classroom)!=0){
            return ResultMsg.SUCCESS();
        }else{
            return ResultMsg.FAILED(0,"修改失败");
        }
    }

    @Override
    public ResultMsg isertinto(Classroom classroom) {
        int classroom1=classroomMapper.isertinto(classroom);
        if (classroom1!=0){
            return ResultMsg.SUCCESS();
        }else {
            return ResultMsg.FAILED(201,"添加失败");
        }
    }

    @Override
    public ResultMsg deleteOne(int classroomId) {

        if(classroomMapper.deleteOne(classroomId)!=0){
            return ResultMsg.SUCCESS();
        }else {
            return ResultMsg.FAILED(201,"删除失败");
        }
    }

    @Override
    public ResultMsg deleteMul(List<Integer> classroomIds) {
        if (classroomMapper.deleteMul(classroomIds)!= 0) {
            return ResultMsg.SUCCESS();
        } else {
            return ResultMsg.FAILED(201, "删除失败");
        }
    }

    @Override
    public ResultMsg selectDim(int page,int limit,String classroomName,String classroomType,Integer classroomStatus) {
        List<Classroom> classroomList2=classroomMapper.selectDim((page-1)*limit,limit,classroomName,classroomType,classroomStatus);
        if (classroomList2!=null){
            return ResultMsg.SUCCESS(0,classroomList2,classroomList2.size());
        }else{
            return ResultMsg.FAILED(201,"查询失败");
        }
    }

    @Override
    public ResultMsg updateStatus(int classroomId, int classroomStatus) {
        if(classroomMapper.updateStatus(classroomId,classroomStatus)!=0){
            return ResultMsg.SUCCESS();
        }
        return ResultMsg.FAILED(201,"修改失败");
    }

    @Override
    public ResultMsg updateStatusMul( List<Integer> classroomIds,Integer classroomStatus) {
        if(classroomMapper.updateStatusMul(classroomIds,classroomStatus)!=0){
            return ResultMsg.SUCCESS();
        }
        return ResultMsg.FAILED(201,"修改失败");
    }
}
